//
//  YCNavigationController.swift
//  WeiboDemo
//
//  Created by 尹成 on 2017/1/6.
//  Copyright © 2017年 yc. All rights reserved.
//

import UIKit

class YCNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationBar.isHidden = true
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //setRootViewController 会调用一次该方法,所以需要将根控制器做特殊处理
        if childViewControllers.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            // 判断控制器类型
            if let vc = viewController as? YCMainViewController {
                var titleStr = "返回"
                if childViewControllers.count == 1 {
                    titleStr = childViewControllers.first?.title ?? titleStr
                }
                
                //取出自定义item
                vc.yctitleItem.leftBarButtonItem = UIBarButtonItem(title: titleStr as NSString,
                                                                   target: self,
                                                                   action: #selector(popBack),
                                                                   isBack:true)
            }
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func popBack(){
        popViewController(animated: true)
    }
    
    
}
